package com.hxzy.service.impl;

import com.hxzy.entity.TbPanel;
import com.hxzy.mapper.TbPanelMapper;
import com.hxzy.service.TbPanelService;
import com.hxzy.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TbPanelServiceImpl implements TbPanelService {
    @Override
    public TbPanel selectByPrimaryKey(Integer id) {
        TbPanel tbPanel=null;
        try (SqlSession  session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelMapper mapper = session.getMapper(TbPanelMapper.class);
            tbPanel=mapper.selectByPrimaryKey(id);
        }
        return tbPanel;
    }

    @Override
    public boolean insert(TbPanel record) {
        int count=0;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelMapper mapper = session.getMapper(TbPanelMapper.class);
            count=mapper.insert(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(TbPanel record) {
        int count=0;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelMapper mapper = session.getMapper(TbPanelMapper.class);
            count=mapper.updateByPrimaryKeySelective(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKey(TbPanel record) {
        int count=0;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelMapper mapper = session.getMapper(TbPanelMapper.class);
            count=mapper.updateByPrimaryKey(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public List<TbPanel> search() {
        List<TbPanel> search=null;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelMapper mapper = session.getMapper(TbPanelMapper.class);
            search = mapper.search();
            session.commit();
        }
        return search;
    }

    @Override
    public List<TbPanel> searchByCondition(TbPanel tbPanel) {
        List<TbPanel> list;
        try (SqlSession session=MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelMapper mapper = session.getMapper(TbPanelMapper.class);
            list = mapper.searchByCondition(tbPanel);
        }
        return list;
    }
}
